/**
 * Copyright 2016-2017 TVI Go Easy.
 * Created on 2017/4/14 01:44
 */
package org.mechanic.fund.domain.system.manager;

import org.apache.commons.lang3.builder.ToStringBuilder;
import org.mechanic.fund.domain.BaseEntity;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.ManyToMany;
import javax.persistence.Table;
import java.util.Set;

/**
 * 系统权限实体
 *
 * @author mechanic
 * @version 0.0.1
 */
@Entity
@Table(name = "sys_permission")
public class Permission extends BaseEntity {

    private static final long serialVersionUID = -2104893873616939956L;
    /**
     * 名称
     */
    @Column(name = "name")
    private String name;
    /**
     * 描述
     */
    @Column(name = "description")
    private String description;

    /**
     * 角色
     */
    //TODO:多对多映射级联删除只删除中间表该怎么处理？
    @ManyToMany(mappedBy = "permissions",cascade= {CascadeType.PERSIST, CascadeType.MERGE})
    private Set<Role> roles;

    public Permission() {
    }

    public Permission(String name, String description) {
        super();
        this.name = name;
        this.description = description;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public Set<Role> getRoles() {
        return roles;
    }

    public void setRoles(Set<Role> roles) {
        this.roles = roles;
    }

    @Override
    public String toString() {
        return ToStringBuilder.reflectionToString(this);
    }
}
